package java8Test.function.lambda.part2;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class RunnableLambdaTest {

    private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
    private ExecutorService executorService = Executors.newSingleThreadExecutor();
    private static Map<Integer, Integer> integerIntegerMap = new HashMap<>();
    private static Map<Integer, Map<Integer, Integer>> integerMapMap = new HashMap<>();

    public static void main(String[] args) {
        RunnableLambdaTest runnableTest = new RunnableLambdaTest();
        runnableTest.testRun(runnableTest::doRun);

        Integer integer = integerIntegerMap.computeIfAbsent(1, k -> 1);
        System.out.println(integer);
        Map<Integer, Integer> integerIntegerMap = integerMapMap.computeIfAbsent(1, k -> new HashMap<>());
        System.out.println(integerIntegerMap);
    }

    public void testRun(Runnable runnable) {
        executorService.submit(runnable);
        scheduledExecutorService.scheduleAtFixedRate(runnable, 1, 1, TimeUnit.SECONDS);
    }

    public void doRun() {
        System.out.println("test run " + Thread.currentThread().getName());
    }
}
